<template>
  <div class="box">
    <div class="title">
      <div class="titleText">
        <van-icon class="icon" name="arrow-left" @click="returnFn" />我的
      </div>
      <div class="userInfo">
        <div class="face">
          <img
            :src="imgUrl + info.userInfo.avatar"
            width="70"
            height="70"
            alt=""
          />

          <img
            v-if="info.userInfo.auth == '1'"
            class="attestation"
            src="@/assets/image/attestation1.png"
            alt=""
          />
          <img
            v-else
            class="attestation"
            src="@/assets/image/attestation2.png"
            alt=""
          />
          <div>
            <span v-if="info.userInfo.auth == '1'">已认证</span>
            <span v-else>未认证</span>
          </div>
        </div>
        <div class="info">
          <div>{{ info.userInfo.username }}</div>
          <div style="margin-top: 10px">
            邀请码：{{ info.userInfo.code }}
            <span
              v-clipboard:copy="info.userInfo.code"
              v-clipboard:success="onCopy"
              v-clipboard:error="onError"
              >复制邀请码</span
            >
          </div>
        </div>
      </div>
    </div>
    <div class="content" v-if="info.data.puser">
      <div class="text">我的上级</div>
      <div class="member">
        <img
          :src="imgUrl + info.data.puser.avatar"
          width="70"
          height="70"
          alt=""
        />
        <div>
          <span>{{ info.data.puser.username }}</span>
        </div>
      </div>
    </div>
    <div class="content">
      <div class="text">我的成员</div>
      <div class="member" v-for="item in info.data.userTeam" :key="item.id">
        <img :src="imgUrl + item.avatar" width="70" height="70" alt="" />
        <div>
          <span>{{ item.username }}</span>
          <span
            >交易次数： <span class="color">{{ item.payCount }}</span> 次</span
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { defineComponent, reactive, getCurrentInstance, onMounted } from "vue";
import { useRouter } from "vue-router";
import { getInfoTeam, imgUrl } from "../../../api/http.js";

export default defineComponent({
  setup() {
    const { proxy } = getCurrentInstance();
    const info = reactive({
      userInfo: {},
      data: {},
    });
    const router = useRouter();
    const returnFn = () => {
      router.go(-1);
    };
    const onCopy = () => {
      proxy.$toast.success("复制成功");
    };
    const onError = () => {
      proxy.$toast.fail("复制失败");
    };
    const getInfo = async () => {
      const userInfo = JSON.parse(localStorage.getItem("info"));
      info.userInfo = userInfo;
      const { data } = await getInfoTeam();
      info.data = data;
      console.log(info);
    };
    onMounted(() => {
      getInfo();
    });
    return {
      info,
      onCopy,
      onError,
      returnFn,
      imgUrl,
    };
  },
});
</script>

<style lang="less" scoped>
.box {
  min-height: 100vh;
  background-color: #f1f0eb;
  .title {
    width: 100%;
    min-height: 180px;
    background-image: url(../../../assets/image/my.png);
    background-repeat: no-repeat;
    background-size: 100% auto;
    background-position: bottom center;
    background-color: #f1f0eb;

    .titleText {
      width: 100%;
      height: 60px;
      font-size: 1.125rem;
      font-family: PingFang SC;
      font-weight: bold;
      color: #444;
      text-align: center;
      line-height: 60px;
      position: relative;
      padding: 0 4%;

      .icon {
        position: absolute;
        top: 50%;
        left: 10px;
        font-size: 1.5rem;
        transform: translateY(-50%);
      }
    }

    .userInfo {
      width: 100%;
      padding: 0 4%;
      display: flex;
      justify-content: space-between;
      align-items: center;

      .face {
        width: 76px;
        height: 76px;
        border-radius: 50%;
        padding: 3px;
        background-color: #fff;
        position: relative;

        img {
          border-radius: 50%;
        }

        .attestation {
          width: 25px;
          height: 25px;
          position: absolute;
          right: 0;
          bottom: 0;
        }
        span {
          display: block;
          width: 100%;
          font-size: 0.9rem;
          font-family: PingFang SC;
          font-weight: 500;
          color: #999999;
          text-align: center;
          margin-top: 5px;
        }
      }

      .info {
        div {
          font-size: 1rem;
          font-family: PingFang SC;
          font-weight: 700;
          color: #444444;

          span {
            font-size: 0.9rem;
            font-family: PingFang SC;
            font-weight: 400;
            text-decoration: underline;
            color: #444444;
            margin-left: 10px;
          }
        }
      }
    }
  }
  .content {
    width: 100%;
    padding: 0 4%;
    margin-top: 10px;

    .text {
      font-size: 1.1rem;
      font-family: PingFang SC;
      font-weight: 500;
      color: #333333;
      margin: 20px 0;
    }
    .member {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      padding: 15px 10px;
      margin-top: 5px;
      background-color: var(--backColor);
      border-radius: 20px;
      color: var(--textColor);

      img {
        margin-left: 10px;
      }

      & > div {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: flex-start;
        margin-left: 20px;

        .color {
          color: #fea802;
        }

        & > span:nth-child(1) {
          font-size: 1rem;
          font-family: PingFang SC;
          font-weight: bold;
        }
        & > span:nth-child(2) {
          margin-top: 10px;
          font-size: 0.8rem;
          font-family: PingFang SC;
          font-weight: 500;
          color: var(--textColorTwo);
        }
      }
    }
  }
}
</style>
